home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / MERGE1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.0 KB  |  38 lines

  1. /*  merge1.c - external sort for a text file */
  2. #include   "stdio.h"
  3. #include   "cminor.h"
  4. #include   "merge1.h"
  5.  
  6. int  (*compfun) () ;        /* address of compare function */
  7. int  strcmp() ;         /* library string compare function */
  8. char scra[68] = "scra" ;        /* prefixes for each word */
  9. char scrb[68] = "scrb" ;
  10.  
  11. main(argc,argv)
  12.   int    argc ;            /* number of words in command line */
  13.   char    *argv[] ;        /* pointers to each word */
  14.   {
  15.      /* check to see that file names were specified */
  16.      if( argc < 3 )
  17.     {  printf(" need file names \n") ;
  18.        printf(" USAGE:   merge1   input-file   output-file  \n") ;
  19.        exit( 1 ) ;
  20.     }
  21.      compfun = strcmp ;     /* use strings compare function */
  22.      dosort(argv[1],argv[2]) ;
  23.   }
  24.  
  25.  
  26. int dosort(fromfile,tofile)
  27.   char    fromfile[] ;        /* input for sort */
  28.   char    tofile[] ;        /* put the output here */
  29.   {
  30.      int nruns ;
  31.                 /* form runs from input file */
  32.      nruns = formruns(fromfile,scra,tofile) ;
  33.                 /* now merge runs */
  34.      domerge(scra,scrb,tofile,nruns) ;
  35.   }
  36.  
  37.  
  38.